﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRSystem.DBAccess;
using HRSystem.Entity;

namespace HRSystem
{
    public partial class FormPersonDetail : Form
    {
        private int id = 0;
        private BaseInfoAccess baseInfoAccess = new BaseInfoAccess();
        private ResultRecordAccess resultRecordAccess = new ResultRecordAccess();
        private OperateProcessRecodeAccess operateProcessRecodeAccess = new OperateProcessRecodeAccess();
        private ResumeAccess resumeAccess = new ResumeAccess();
        private FormSearch frmSeach;

        public FormPersonDetail(int id, FormSearch frm)
        {
            InitializeComponent();
            frmSeach = frm;
            this.id = id;
        }

        private void FormPersonDetail_Load(object sender, EventArgs e)
        {
            this.Text = id == 0 ? "创建" : "修改";
            Init();
        }

        public void Init()
        {
            InitResumeLabel();
            InitContactWay();
            InitResume();
            InitPhoneTalkRecord();
            InitOperateProcessRecode();
            InitResultRecord();
            InitBaseInfo();
        }

        #region （一）个人基本信息

        private void InitBaseInfo()
        {
            PageCommon.FormatDateTimePickerByYearMonth(dtpBaseBirthday);

            cboBaseGender.Items.Add("男");
            cboBaseGender.Items.Add("女");
            cboBaseGender.SelectedIndex = 0;

            BindBaseInfo();

            txtBaseChineseName.Focus();
        }

        private void BindBaseInfo()
        {
            if (id != 0)
            {
                Person person = baseInfoAccess.GetPerson(id);
                BaseInfo baseInfo = person.myBaseInfo;
                txtBaseChineseName.Text = baseInfo.BaseChineseName;
                txtBaseEnglishName.Text = baseInfo.BaseEnglishName;
                cboBaseGender.SelectedItem = baseInfo.BaseGender;
                txtBaseHighestEducation.Text = baseInfo.BaseHighestEducation;
                txtBaseGraduatedSchool.Text = baseInfo.BaseGraduatedSchool;
                txtBaseSpecialty.Text = baseInfo.BaseSpecialty;
                dtpBaseBirthday.Value = baseInfo.BaseBirthday;
                txtBaseWorkExperienceYear.Text = baseInfo.BaseWorkExperienceYear.ToString();
                txtBaseCurrentLocation.Text = baseInfo.BaseCurrentLocation;
                txtExpandNationality.Text = baseInfo.ExpandNationality;
                txtExpandNativePlace.Text = baseInfo.ExpandNativePlace;
                txtExpandPoliticsFace.Text = baseInfo.ExpandPoliticsFace;
                txtExpandEthnic.Text = baseInfo.ExpandEthnic;
                txtExpandMarryBirthBaby.Text = baseInfo.ExpandMarryBirthBaby;
                txtExpandHealth.Text = baseInfo.ExpandHealth;
                txtExpandBloodType.Text = baseInfo.ExpandBloodType;
                txtExpandHobby.Text = baseInfo.ExpandHobby;

                chkIsDataCollect.Checked = baseInfo.IsDataCollect;
                txtDataCollectCertificate.Text = baseInfo.DataCollectCertificate;

                chkIsEducationSurvey.Checked = baseInfo.IsEducationSurvey;
                txtEducationSurveyOperatePerson.Text = baseInfo.EducationSurveyOperatePerson;
                txtEducationSurveyOrganization.Text = baseInfo.EducationSurveyOrganization;
                txtEducationSurveyResult.Text = baseInfo.EducationSurveyResult;

                chkIsSurvey.Checked = baseInfo.IsSurvey;
                dtpSurveyTime.Value = baseInfo.SurveyTime;
                txtSurveyOperatePerson.Text = baseInfo.SurveyOperatePerson;
                txtSurveyWorkTruth.Text = baseInfo.SurveyWorkTruth;
                txtSurveyEveryTruth.Text = baseInfo.SurveyEveryTruth;
                txtSurveyExceptionRemark.Text = baseInfo.SurveyExceptionRemark;

                ResumeLabel resumeLabel = person.myResumeLabel;
                txtResumeKeyword.Text = resumeLabel.ResumeKeyword;
                txtResumeSource.Text = resumeLabel.ResumeSource;
                dtpResumeGetTime.Value = resumeLabel.ResumeGetTime;

                ContactWay contactWay = person.myContactWay;
                txtContactMobilePhone.Text = contactWay.ContactMobilePhone;
                txtContactEmail.Text = contactWay.ContactEmail;
                txtContactQQMSNICQNumber.Text = contactWay.ContactQQMSNICQNumber;
                txtContactAddress.Text = contactWay.ContactAddress;

                PhoneTalkRecord phoneTalkRecord = person.myPhoneTalkRecord;
                dtpRecordTime.Value = phoneTalkRecord.RecordTime;
                txtRecordPerson.Text = phoneTalkRecord.RecordPerson;
                txtRecordFamily.Text = phoneTalkRecord.RecordFamily;
                txtRecordCharacter.Text = phoneTalkRecord.RecordCharacter;
                txtRecordCommunication.Text = phoneTalkRecord.RecordCommunication;
                txtJobWish.Text = phoneTalkRecord.JobWish;
                txtJobDepartureReason.Text = phoneTalkRecord.JobDepartureReason;
                txtJobTargetPosition.Text = phoneTalkRecord.JobTargetPosition;
                txtSalarPresent.Text = phoneTalkRecord.SalarPresent.ToString();
                txtSalarTarget.Text = phoneTalkRecord.SalarTarget.ToString();
                txtSpecialIssue.Text = phoneTalkRecord.SpecialIssue;
                txtAuditionTime.Text = phoneTalkRecord.AuditionTime;
                chkIsAcceptSurvey.Checked = phoneTalkRecord.IsAcceptSurvey;
            }

        }

        private bool CheckBaseInfoNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtBaseChineseName.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入中文名字。");
                txtBaseChineseName.Focus();
            }
            //else if (string.IsNullOrEmpty(txtBaseEnglishName.Text.Trim()))
            //{
            //    PageCommon.ShowMessageByOK("请输入英文名字。");
            //    txtBaseEnglishName.Focus();
            //}
            else if (string.IsNullOrEmpty(txtBaseHighestEducation.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入最高学历。");
                txtBaseHighestEducation.Focus();
            }
            else if (string.IsNullOrEmpty(txtBaseGraduatedSchool.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入毕业学校。");
                txtBaseGraduatedSchool.Focus();
            }
            //else if (string.IsNullOrEmpty(txtBaseSpecialty.Text.Trim()))
            //{
            //    PageCommon.ShowMessageByOK("请输入专业。");
            //    txtBaseSpecialty.Focus();
            //}
            //else if (string.IsNullOrEmpty(txtBaseWorkExperienceYear.Text.Trim()))
            //{
            //    PageCommon.ShowMessageByOK("请输入工作经验。");
            //    txtBaseWorkExperienceYear.Focus();
            //}
            //else if (string.IsNullOrEmpty(txtBaseCurrentLocation.Text.Trim()))
            //{
            //    PageCommon.ShowMessageByOK("请输入现在所在地。");
            //    txtBaseCurrentLocation.Focus();
            //}
            //else if (string.IsNullOrEmpty(txtExpandNativePlace.Text.Trim()))
            //{
            //    PageCommon.ShowMessageByOK("请输入籍贯。");
            //    txtExpandNativePlace.Focus();
            //}
            //else if (string.IsNullOrEmpty(txtExpandMarryBirthBaby.Text.Trim()))
            //{
            //    PageCommon.ShowMessageByOK("请输入婚育情况。");
            //    txtExpandMarryBirthBaby.Focus();
            //}
            else
                isNotNull = true;
            return isNotNull;
        }

        private void btnBaseInfoSave_Click(object sender, EventArgs e)
        {
            if (CheckBaseInfoNull())
            {
                BaseInfo baseInfo = new BaseInfo();
                baseInfo.ID = id;
                //（1）基础数据
                baseInfo.BaseChineseName = txtBaseChineseName.Text.Trim();
                baseInfo.BaseEnglishName = txtBaseEnglishName.Text.Trim();
                baseInfo.BaseGender = cboBaseGender.SelectedItem.ToString();
                baseInfo.BaseHighestEducation = txtBaseHighestEducation.Text.Trim();
                baseInfo.BaseGraduatedSchool = txtBaseGraduatedSchool.Text.Trim();
                baseInfo.BaseSpecialty = txtBaseSpecialty.Text.Trim();
                baseInfo.BaseBirthday = dtpBaseBirthday.Value;
                if(!string.IsNullOrEmpty(txtBaseWorkExperienceYear.Text.Trim()))
                baseInfo.BaseWorkExperienceYear = Convert.ToInt32(txtBaseWorkExperienceYear.Text.Trim());
                baseInfo.BaseCurrentLocation = txtBaseCurrentLocation.Text.Trim();
                //（2）扩展数据
                baseInfo.ExpandNationality = txtExpandNationality.Text.Trim();
                baseInfo.ExpandNativePlace = txtExpandNativePlace.Text.Trim();
                baseInfo.ExpandPoliticsFace = txtExpandPoliticsFace.Text.Trim();
                baseInfo.ExpandEthnic = txtExpandEthnic.Text.Trim();
                baseInfo.ExpandMarryBirthBaby = txtExpandMarryBirthBaby.Text.Trim();
                baseInfo.ExpandHealth = txtExpandHealth.Text.Trim();
                baseInfo.ExpandBloodType = txtExpandBloodType.Text.Trim();
                baseInfo.ExpandHobby = txtExpandHobby.Text.Trim();

                if (baseInfoAccess.AddOrUpdateBaseInfo(baseInfo))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                    if (id != 0)
                    {
                        frmSeach.BindDate();
                    }
                    id = baseInfo.ID;
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        #endregion
        #region （二）简历标签

        private void InitResumeLabel()
        {
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpResumeGetTime);
        }

        private bool CheckResumeLabelNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtResumeKeyword.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入关键字。");
                txtResumeKeyword.Focus();
            }
            else if (string.IsNullOrEmpty(txtResumeSource.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入简历来源。");
                txtResumeSource.Focus();
            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void btnResume_Click(object sender, EventArgs e)
        {
            if (CheckResumeLabelNull())
            {
                ResumeLabel resumeLabel = new ResumeLabel();
                resumeLabel.ID = id;

                resumeLabel.ResumeKeyword = txtResumeKeyword.Text.Trim();
                resumeLabel.ResumeSource = txtResumeSource.Text.Trim();
                resumeLabel.ResumeGetTime = dtpResumeGetTime.Value;

                if (baseInfoAccess.AddOrUpdateResumeLabel(resumeLabel))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        #endregion
        #region  （三）联系方式

        private void InitContactWay()
        {

        }

        private bool CheckContactWayNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtContactMobilePhone.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入手机号码。");
                txtContactMobilePhone.Focus();
            }
            else if (string.IsNullOrEmpty(txtContactEmail.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入电子邮箱。");
                txtContactEmail.Focus();
            }
            else if (string.IsNullOrEmpty(txtContactQQMSNICQNumber.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入QQ/MSN/ICQ号码。");
                txtContactQQMSNICQNumber.Focus();

            }
            else if (string.IsNullOrEmpty(txtContactAddress.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入地址。");
                txtContactAddress.Focus();
            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void btnContactWaySave_Click(object sender, EventArgs e)
        {
            if (CheckContactWayNull())
            {
                ContactWay contactWay = new ContactWay();
                contactWay.ID = id;

                contactWay.ContactMobilePhone = txtContactMobilePhone.Text.Trim();
                contactWay.ContactEmail = txtContactEmail.Text.Trim();
                contactWay.ContactQQMSNICQNumber = txtContactQQMSNICQNumber.Text.Trim();
                contactWay.ContactAddress = txtContactAddress.Text.Trim();

                if (baseInfoAccess.AddOrUpdateContactWay(contactWay))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        #endregion
        #region  （四）个人简历

        private void InitResume()
        {
            PageCommon.FormatDateTimePickerByYearMonth(dtpEducationStartTime);
            PageCommon.FormatDateTimePickerByYearMonth(dtpEducationEndTime);
            PageCommon.FormatDateTimePickerByYearMonth(dtpWorkStartTime);
            PageCommon.FormatDateTimePickerByYearMonth(dtpWorkEndTime);
            PageCommon.FormatDateTimePickerByYearMonth(dtpProjectStartTime);
            PageCommon.FormatDateTimePickerByYearMonth(dtpProjectEndTime);
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpHonourGetTime);
            BindEducation();
            BindWork();
            BindProject();
            BindRelevanceCredential();
            BindHonour();
        }

        /// <summary>
        ///   （10）教育背景
        /// </summary>
        /// 

        private List<Resume> listEducation = new List<Resume>();
        private int educationID = 0;
        private void InitEducationDate(string educationSchoolName, string educationSchoolCharacter, string educationSpecialty, string educationdDgree, string educationStudyStyle, DateTime educationStartTime, DateTime educationEndTime)
        {
            txtEducationSchoolName.Text = educationSchoolName;
            txtEducationSchoolCharacter.Text = educationSchoolCharacter;
            txtEducationSpecialty.Text = educationSpecialty;
            txtEducationdDgree.Text = educationdDgree;
            txtEducationStudyStyle.Text = educationStudyStyle;
            dtpEducationStartTime.Value = educationStartTime;
            dtpEducationEndTime.Value = educationEndTime;
        }

        private void BindEducation()
        {
            if (id != 0)
            {
                listEducation = resumeAccess.GetResumes(id, 0);
                dtvEducationSchool.Visible = true;
                dtvEducationSchool.RowHeadersVisible = false;
                dtvEducationSchool.DataSource = listEducation;
            }
            else
            {
                dtvEducationSchool.Visible = false;
            }
        }

        private void dtvEducationSchool_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dtvEducationSchool.Columns.Clear();
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("毕业学校", "EducationSchoolName", "EducationSchoolName", true));
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("学校性质", "EducationSchoolCharacter", "EducationSchoolCharacter", true));
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("专业", "EducationSpecialty", "EducationSpecialty", true));
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("学历/学位", "EducationdDgree", "EducationdDgree", true));
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("学习形式", "EducationStudyStyle", "EducationStudyStyle", true));
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("起始年月", "EducationStartTime", "EducationStartTime", true));
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("终止年月", "EducationEndTime", "EducationEndTime", true));
            dtvEducationSchool.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dtvEducationSchool.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dtvEducationSchool.Columns["EducationSchoolName"].Width = 100;
            dtvEducationSchool.Columns["EducationSchoolCharacter"].Width = 90;
            dtvEducationSchool.Columns["EducationSpecialty"].Width = 60;
            dtvEducationSchool.Columns["EducationdDgree"].Width = 90;
            dtvEducationSchool.Columns["EducationStudyStyle"].Width = 90;
            dtvEducationSchool.Columns["EducationStartTime"].Width = 120;
            dtvEducationSchool.Columns["EducationEndTime"].Width = 120;
            dtvEducationSchool.Columns["detail"].Width = 42;
            dtvEducationSchool.ReadOnly = true;
            dtvEducationSchool.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private bool CheckEducationNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtEducationSchoolName.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入毕业学校。");
                txtEducationSchoolName.Focus();
            }
            else if (string.IsNullOrEmpty(txtEducationSchoolCharacter.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入学校性质。");
                txtEducationSchoolCharacter.Focus();
            }
            else if (string.IsNullOrEmpty(txtEducationSpecialty.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入专业。");
                txtEducationSpecialty.Focus();
            }
            else if (string.IsNullOrEmpty(txtEducationdDgree.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入学历/学位。");
                txtEducationdDgree.Focus();
            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void dtvEducationSchool_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 7) && e.RowIndex != -1)
            {
                educationID = Convert.ToInt32(dtvEducationSchool.CurrentRow.Cells["id"].Value);
                foreach (Resume resume in listEducation)
                {
                    if (resume.ID == educationID)
                    {
                        InitEducationDate(resume.EducationSchoolName, resume.EducationSchoolCharacter, resume.EducationSpecialty,
                        resume.EducationdDgree, resume.EducationStudyStyle, resume.EducationStartTime, resume.EducationEndTime);
                    }
                }

            }

        }

        private void btnEducationSave_Click(object sender, EventArgs e)
        {
            if (CheckEducationNull())
            {
                Resume resume = new Resume();
                resume.ID = educationID;

                resume.EducationSchoolName = txtEducationSchoolName.Text.Trim();
                resume.EducationSchoolCharacter = txtEducationSchoolCharacter.Text.Trim();
                resume.EducationSpecialty = txtEducationSpecialty.Text.Trim();
                resume.EducationdDgree = txtEducationdDgree.Text.Trim();
                resume.EducationStudyStyle = txtEducationStudyStyle.Text.Trim();
                resume.EducationStartTime = dtpEducationStartTime.Value;
                resume.EducationEndTime = dtpEducationEndTime.Value;
                resume.BaseInfoID = id;
                resume.type = 0;

                if (resumeAccess.AddOrUpdateResume(resume))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                    //id = resume.ID;
                    educationID = 0;
                    InitEducationDate(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, DateTime.Now, DateTime.Now);
                    BindEducation();
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        /// <summary>
        ///   （11）工作经历
        /// </summary>
        /// 

        private List<Resume> listWork = new List<Resume>();
        private int workID = 0;

        private void InitWorkDate(string workCompany, string workPosition, string workRevenue, string workDepartureReason, string workProvePersonAndPosition, string workProvePersonContact, DateTime workStartTime, DateTime workEndTime)
        {
            txtWorkCompany.Text = workCompany;
            txtWorkPosition.Text = workPosition;
            txtWorkRevenue.Text = workRevenue;
            txtWorkDepartureReason.Text = workDepartureReason;
            txtWorkProvePersonAndPosition.Text = workProvePersonAndPosition;
            txtWorkProvePersonContact.Text = workProvePersonContact;
            dtpWorkStartTime.Value = workStartTime;
            dtpWorkEndTime.Value = workEndTime;
        }

        private void BindWork()
        {
            if (id != 0)
            {
                listWork = resumeAccess.GetResumes(id, 1);
                dgvWork.Visible = true;
                dgvWork.RowHeadersVisible = false;
                dgvWork.DataSource = listWork;
            }
            else
            {
                dgvWork.Visible = false;
            }
        }

        private bool CheckWorkNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtWorkCompany.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入提供单位。");
                txtWorkCompany.Focus();
            }
            else if (string.IsNullOrEmpty(txtWorkPosition.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入职位。");
                txtWorkPosition.Focus();
            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void dgvWork_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvWork.Columns.Clear();
            dgvWork.Columns.Add(PageCommon.BuildColumn("供职单位/公司", "WorkCompany", "WorkCompany", true));
            dgvWork.Columns.Add(PageCommon.BuildColumn("职位", "WorkPosition", "WorkPosition", true));
            dgvWork.Columns.Add(PageCommon.BuildColumn("收入情况", "WorkRevenue", "WorkRevenue", true));
            dgvWork.Columns.Add(PageCommon.BuildColumn("离职原因", "WorkDepartureReason", "WorkDepartureReason", true));
            dgvWork.Columns.Add(PageCommon.BuildColumn("证明人（含职位）", "WorkProvePersonAndPosition", "WorkProvePersonAndPosition", true));
            dgvWork.Columns.Add(PageCommon.BuildColumn("证明人联系方式", "WorkProvePersonContact", "WorkProvePersonContact", true));
            dgvWork.Columns.Add(PageCommon.BuildColumn("起始年月", "WorkStartTime", "WorkStartTime", true));
            dgvWork.Columns.Add(PageCommon.BuildColumn("终止年月", "WorkEndTime", "WorkEndTime", true));
            dgvWork.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvWork.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvWork.Columns["detail"].Width = 42;
            dgvWork.ReadOnly = true;
            dgvWork.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvWork_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 8) && e.RowIndex != -1)
            {
                workID = Convert.ToInt32(dgvWork.CurrentRow.Cells["id"].Value);
                foreach (Resume resume in listWork)
                {
                    if (resume.ID == workID)
                    {
                        InitWorkDate(resume.WorkCompany, resume.WorkPosition, resume.WorkRevenue, resume.WorkDepartureReason,
                            resume.WorkProvePersonAndPosition, resume.WorkProvePersonContact, resume.WorkStartTime, resume.WorkEndTime);
                    }
                }

            }
        }

        private void btnWorkSave_Click(object sender, EventArgs e)
        {
            if (CheckWorkNull())
            {
                Resume resume = new Resume();
                resume.ID = workID;

                resume.WorkCompany = txtWorkCompany.Text.Trim();
                resume.WorkPosition = txtWorkPosition.Text.Trim();
                resume.WorkRevenue = txtWorkRevenue.Text.Trim();
                resume.WorkDepartureReason = txtWorkDepartureReason.Text.Trim();
                resume.WorkProvePersonAndPosition = txtWorkProvePersonAndPosition.Text.Trim();
                resume.WorkProvePersonContact = txtWorkProvePersonContact.Text.Trim();
                resume.WorkStartTime = dtpWorkStartTime.Value;
                resume.WorkEndTime = dtpWorkEndTime.Value;
                resume.BaseInfoID = id;
                resume.type = 1;

                if (resumeAccess.AddOrUpdateResume(resume))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                    workID = 0;
                    InitWorkDate(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, DateTime.Now, DateTime.Now);
                    BindWork();
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        /// <summary>
        ///   （12）项目经验
        /// </summary>
        /// 

        private List<Resume> listProject = new List<Resume>();
        private int projectID = 0;

        private void InitProjectDate(string projectName, string projectIntro, string projectDetail, DateTime projectStartTime, DateTime projectEndTime)
        {
            txtProjectName.Text = projectName;
            txtProjectIntro.Text = projectIntro;
            txtProjectDetail.Text = projectDetail;
            dtpProjectStartTime.Value = projectStartTime;
            dtpProjectEndTime.Value = projectEndTime;
        }

        private void BindProject()
        {
            if (id != 0)
            {
                listProject = resumeAccess.GetResumes(id, 2);
                dgvProject.Visible = true;
                dgvProject.RowHeadersVisible = false;
                dgvProject.DataSource = listProject;
            }
            else
            {
                dgvProject.Visible = false;
            }
        }

        private void dgvProject_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvProject.Columns.Clear();
            dgvProject.Columns.Add(PageCommon.BuildColumn("项目名称", "ProjectName", "ProjectName", true));
            dgvProject.Columns.Add(PageCommon.BuildColumn("项目简介", "ProjectIntro", "ProjectIntro", true));
            dgvProject.Columns.Add(PageCommon.BuildColumn("责任描述", "ProjectDetail", "ProjectDetail", true));
            dgvProject.Columns.Add(PageCommon.BuildColumn("起始年月", "ProjectStartTime", "ProjectStartTime", true));
            dgvProject.Columns.Add(PageCommon.BuildColumn("终止年月", "ProjectEndTime", "ProjectEndTime", true));
            dgvProject.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvProject.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvProject.Columns["detail"].Width = 42;
            dgvProject.ReadOnly = true;
            dgvProject.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvProject_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 5) && e.RowIndex != -1)
            {
                projectID = Convert.ToInt32(dgvProject.CurrentRow.Cells["id"].Value);
                foreach (Resume resume in listProject)
                {
                    if (resume.ID == projectID)
                    {
                        InitProjectDate(resume.ProjectName, resume.ProjectIntro, resume.ProjectDetail, resume.ProjectStartTime, resume.ProjectEndTime);
                    }
                }

            }
        }

        private void btnProjectSave_Click(object sender, EventArgs e)
        {
            //if (CheckEducationNull())
            //{
            Resume resume = new Resume();
            resume.ID = projectID;

            resume.ProjectName = txtProjectName.Text.Trim();
            resume.ProjectIntro = txtProjectIntro.Text.Trim();
            resume.ProjectDetail = txtProjectDetail.Text.Trim();
            resume.ProjectStartTime = dtpProjectStartTime.Value;
            resume.ProjectEndTime = dtpProjectEndTime.Value;
            resume.BaseInfoID = id;
            resume.type = 2;

            if (resumeAccess.AddOrUpdateResume(resume))
            {
                PageCommon.ShowMessageByOK("保存成功。");
                projectID = 0;
                InitProjectDate(string.Empty, string.Empty, string.Empty, DateTime.Now, DateTime.Now);
                BindProject();
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
            //}
        }

        /// <summary>
        ///   ( 13 )相关证书
        /// </summary>
        /// 

        private List<Resume> listRelevanceCredential = new List<Resume>();
        private int relevanceCredentialID = 0;

        private void InitRelevanceCredentialDate(string relevanceCredential)
        {
            txtRelevanceCredentials.Text = relevanceCredential;
        }

        private void BindRelevanceCredential()
        {
            if (id != 0)
            {
                listRelevanceCredential = resumeAccess.GetResumes(id, 3);
                dvgRelevanceCredentials.Visible = true;
                dvgRelevanceCredentials.RowHeadersVisible = false;
                dvgRelevanceCredentials.DataSource = listRelevanceCredential;
            }
            else
            {
                dvgRelevanceCredentials.Visible = false;
            }
        }

        private bool CheckRelevanceCredentialsNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtRelevanceCredentials.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入职称、资质、技能证书。");
                txtRelevanceCredentials.Focus();
            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void dvgRelevanceCredentials_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dvgRelevanceCredentials.Columns.Clear();
            dvgRelevanceCredentials.Columns.Add(PageCommon.BuildColumn("职称、资质、技能证书", "RelevanceCredentials", "RelevanceCredentials", true));
            dvgRelevanceCredentials.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dvgRelevanceCredentials.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dvgRelevanceCredentials.Columns["RelevanceCredentials"].Width = 242;
            dvgRelevanceCredentials.Columns["detail"].Width = 42;
            dvgRelevanceCredentials.ReadOnly = true;
            dvgRelevanceCredentials.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvRelevanceCredentials_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 1) && e.RowIndex != -1)
            {
                relevanceCredentialID = Convert.ToInt32(dvgRelevanceCredentials.CurrentRow.Cells["id"].Value);
                foreach (Resume resume in listRelevanceCredential)
                {
                    if (resume.ID == relevanceCredentialID)
                    {
                        InitRelevanceCredentialDate(resume.RelevanceCredentials);
                    }
                }

            }
        }

        private void btnRelevanceCredentialsSave_Click(object sender, EventArgs e)
        {
            if (CheckRelevanceCredentialsNull())
            {
                Resume resume = new Resume();
                resume.ID = relevanceCredentialID;

                resume.RelevanceCredentials = txtRelevanceCredentials.Text.Trim();
                resume.BaseInfoID = id;
                resume.type = 3;

                if (resumeAccess.AddOrUpdateResume(resume))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                    relevanceCredentialID = 0;
                    InitRelevanceCredentialDate(string.Empty);
                    BindRelevanceCredential();
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        /// <summary>
        ///   （14）个人荣誉
        /// </summary>
        /// 

        private List<Resume> listHonour = new List<Resume>();
        private int honourID = 0;

        private void InitHonourDate(string honourName, string honourUnits, string honourReason, string honourLevel, DateTime honourGetTime)
        {
            txtHonourName.Text = honourName;
            txtHonourUnits.Text = honourUnits;
            txtHonourReason.Text = honourReason;
            txtHonourLevel.Text = honourLevel;
            dtpHonourGetTime.Value = honourGetTime;
        }

        private void BindHonour()
        {
            if (id != 0)
            {
                listHonour = resumeAccess.GetResumes(id, 4);
                dgvHonour.Visible = true;
                dgvHonour.RowHeadersVisible = false;
                dgvHonour.DataSource = listHonour;
            }
            else
            {
                dgvHonour.Visible = false;
            }
        }

        private void dgvHonour_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvHonour.Columns.Clear();
            dgvHonour.Columns.Add(PageCommon.BuildColumn("荣誉名称", "HonourName", "HonourName", true));
            dgvHonour.Columns.Add(PageCommon.BuildColumn("荣誉名称", "HonourUnits", "HonourUnits", true));
            dgvHonour.Columns.Add(PageCommon.BuildColumn("荣誉事由", "HonourReason", "HonourReason", true));
            dgvHonour.Columns.Add(PageCommon.BuildColumn("荣誉级别", "HonourLevel", "HonourLevel", true));
            dgvHonour.Columns.Add(PageCommon.BuildColumn("颁授时间", "HonourGetTime", "HonourGetTime", true));
            dgvHonour.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvHonour.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvHonour.Columns["detail"].Width = 42;
            dgvHonour.ReadOnly = true;
            dgvHonour.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }


        private void dgvHonour_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 5) && e.RowIndex != -1)
            {
                honourID = Convert.ToInt32(dgvHonour.CurrentRow.Cells["id"].Value);
                foreach (Resume resume in listHonour)
                {
                    if (resume.ID == honourID)
                    {
                        InitHonourDate(resume.HonourName, resume.HonourUnits, resume.HonourReason, resume.HonourLevel, resume.HonourGetTime);
                    }
                }
            }
        }

        private void btnHonourSave_Click(object sender, EventArgs e)
        {
            //if (CheckEducationNull())
            //{
            Resume resume = new Resume();
            resume.ID = honourID;

            resume.HonourName = txtHonourName.Text.Trim();
            resume.HonourUnits = txtHonourUnits.Text.Trim();
            resume.HonourReason = txtHonourReason.Text.Trim();
            resume.HonourLevel = txtHonourLevel.Text.Trim();
            resume.HonourGetTime = dtpHonourGetTime.Value;
            resume.BaseInfoID = id;
            resume.type = 4;

            if (resumeAccess.AddOrUpdateResume(resume))
            {
                PageCommon.ShowMessageByOK("保存成功。");
                honourID = 0;
                InitHonourDate(string.Empty, string.Empty, string.Empty, string.Empty, DateTime.Now);
                BindHonour();
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
            //  }
        }

        #endregion
        #region  （五）初次电话访谈记录

        private void InitPhoneTalkRecord()
        {
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpRecordTime);
        }

        private bool CheckPhoneTalkRecordNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtRecordPerson.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入访谈人。");
                txtRecordPerson.Focus();
            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void btnPhoneTalkRecord_Click(object sender, EventArgs e)
        {
            if (CheckPhoneTalkRecordNull())
            {
                PhoneTalkRecord phoneTalkRecord = new PhoneTalkRecord();
                phoneTalkRecord.ID = id;

                phoneTalkRecord.RecordTime = dtpRecordTime.Value;
                phoneTalkRecord.RecordPerson = txtRecordPerson.Text.Trim();
                phoneTalkRecord.RecordFamily = txtRecordFamily.Text.Trim();
                phoneTalkRecord.RecordCharacter = txtRecordCharacter.Text.Trim();
                phoneTalkRecord.RecordCommunication = txtRecordCommunication.Text.Trim();
                phoneTalkRecord.JobWish = txtJobWish.Text.Trim();
                phoneTalkRecord.JobDepartureReason = txtJobDepartureReason.Text.Trim();
                phoneTalkRecord.JobTargetPosition = txtJobTargetPosition.Text.Trim();
                phoneTalkRecord.SalarPresent = Convert.ToDouble(txtSalarPresent.Text.Trim());
                phoneTalkRecord.SalarTarget = Convert.ToDouble(txtSalarTarget.Text.Trim());
                phoneTalkRecord.SpecialIssue = txtSpecialIssue.Text.Trim();
                phoneTalkRecord.AuditionTime = txtAuditionTime.Text.Trim();
                phoneTalkRecord.IsAcceptSurvey = chkIsAcceptSurvey.Checked;

                if (baseInfoAccess.AddOrUpdatePhoneTalkRecord(phoneTalkRecord))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        #endregion
        #region（六）操作过程记录

        private void InitOperateProcessRecode()
        {
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpPhoneTime);
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpRecommenTime);
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpWritenTestTime);
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpInterviewTime);
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpSurveyTime);
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpSalaryCommunicationsTime);

            BindPhone();
            BindRecommen();
            BindWritenTest();
            BindInterview();
            BindSalaryCommunicationDate();
        }

        /// <summary>
        /// （21）电话访谈跟进
        /// </summary>
        private List<OperateProcessRecode> listPhone = new List<OperateProcessRecode>();
        private int phoneID = 0;

        private bool CheckInitOperateProcessRecode()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtPhoneOperatePerson.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入访谈操作人。");
                txtPhoneOperatePerson.Focus();
            }
            else if (string.IsNullOrEmpty(txtPhoneContent.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入访谈内容。");
                txtPhoneContent.Focus();
            }
            else if (string.IsNullOrEmpty(txtPhoneResult.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入访谈结果。");
                txtPhoneResult.Focus();
            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void InitPhoneDate(DateTime phoneTime, string phoneOperatePerson, string phoneContent, string phoneResult)
        {
            dtpPhoneTime.Value = phoneTime;
            txtPhoneOperatePerson.Text = phoneOperatePerson;
            txtPhoneContent.Text = phoneContent;
            txtPhoneResult.Text = phoneResult;
        }

        private void BindPhone()
        {
            if (id != 0)
            {
                listPhone = operateProcessRecodeAccess.GetOperateProcessRecodes(id, 0);
                dgvPhone.Visible = true;
                dgvPhone.RowHeadersVisible = false;
                dgvPhone.DataSource = listPhone;
            }
            else
            {
                dgvPhone.Visible = false;
            }
        }

        private void dgvPhone_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvPhone.Columns.Clear();
            dgvPhone.Columns.Add(PageCommon.BuildColumn("时间", "PhoneTime", "PhoneTime", true));
            dgvPhone.Columns.Add(PageCommon.BuildColumn("操作人", "PhoneOperatePerson", "PhoneOperatePerson", true));
            dgvPhone.Columns.Add(PageCommon.BuildColumn("访谈内容", "PhoneContent", "PhoneContent", true));
            dgvPhone.Columns.Add(PageCommon.BuildColumn("结果", "PhoneResult", "PhoneResult", true));
            dgvPhone.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvPhone.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvPhone.Columns["detail"].Width = 42;
            dgvPhone.ReadOnly = true;
            dgvPhone.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvPhone_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 4) && e.RowIndex != -1)
            {
                phoneID = Convert.ToInt32(dgvPhone.CurrentRow.Cells["id"].Value);
                foreach (OperateProcessRecode operateProcessRecode in listPhone)
                {
                    if (operateProcessRecode.ID == phoneID)
                    {
                        InitPhoneDate(operateProcessRecode.PhoneTime, operateProcessRecode.PhoneOperatePerson, operateProcessRecode.PhoneContent, operateProcessRecode.PhoneResult);
                    }
                }
            }
        }

        private void btnOperateProcessRecodeSave_Click(object sender, EventArgs e)
        {
            if (CheckInitOperateProcessRecode())
            {
                OperateProcessRecode operateProcessRecode = new OperateProcessRecode();
                operateProcessRecode.ID = phoneID;
                operateProcessRecode.BaseInfoID = id;
                operateProcessRecode.type = 0;
                //（21）电话访谈跟进
                operateProcessRecode.PhoneTime = dtpPhoneTime.Value;
                operateProcessRecode.PhoneOperatePerson = txtPhoneOperatePerson.Text.Trim();
                operateProcessRecode.PhoneContent = txtPhoneContent.Text.Trim();
                operateProcessRecode.PhoneResult = txtPhoneResult.Text.Trim();

                if (operateProcessRecodeAccess.AddOrUpdateOperateProcessRecode(operateProcessRecode))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                    phoneID = 0;
                    InitPhoneDate(DateTime.Now, string.Empty, string.Empty, string.Empty);
                    BindPhone();
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        /// <summary>
        /// （22）资料收集
        /// </summary>
        private void btnDataCollectSave_Click(object sender, EventArgs e)
        {
            //（22）资料收集

            BaseInfo baseInfo = new BaseInfo();
            baseInfo.ID = id;
            baseInfo.IsDataCollect = chkIsDataCollect.Checked;
            baseInfo.DataCollectCertificate = txtDataCollectCertificate.Text.Trim();

            if (baseInfoAccess.UpdateDataCollect(baseInfo))
            {
                PageCommon.ShowMessageByOK("保存成功。");
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
        }

        /// <summary>
        ///（23）简历推荐
        /// </summary>

        private List<OperateProcessRecode> listRecommen = new List<OperateProcessRecode>();
        private int recommenID = 0;

        private void InitRecommenDate(bool isRecommen, DateTime recommenTime, string recommenOperatePerson, string recommenCompany, string recommenPosition, string recommenResult)
        {
            chkIsRecommen.Checked = isRecommen;
            dtpRecommenTime.Value = recommenTime;
            txtRecommenOperatePerson.Text = recommenOperatePerson;
            txtRecommenCompany.Text = recommenCompany;
            txtRecommenPosition.Text = recommenPosition;
            txtRecommenResult.Text = recommenResult;
        }

        private void BindRecommen()
        {
            if (id != 0)
            {
                listRecommen = operateProcessRecodeAccess.GetOperateProcessRecodes(id, 2);
                dgvRecommen.Visible = true;
                dgvRecommen.RowHeadersVisible = false;
                dgvRecommen.DataSource = listRecommen;
            }
            else
            {
                dgvRecommen.Visible = false;
            }
        }

        private void dgvRecommen_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvRecommen.Columns.Clear();
            dgvRecommen.Columns.Add(PageCommon.BuildColumn("是否推荐", "IsRecommen", "IsRecommen", true));
            dgvRecommen.Columns.Add(PageCommon.BuildColumn("推荐时间", "RecommenTime", "RecommenTime", true));
            dgvRecommen.Columns.Add(PageCommon.BuildColumn("操作人", "RecommenOperatePerson", "RecommenOperatePerson", true));
            dgvRecommen.Columns.Add(PageCommon.BuildColumn("推荐单位/公司", "RecommenCompany", "RecommenCompany", true));
            dgvRecommen.Columns.Add(PageCommon.BuildColumn("推荐岗位", "RecommenPosition", "RecommenPosition", true));
            dgvRecommen.Columns.Add(PageCommon.BuildColumn("结果", "RecommenResult", "RecommenResult", true));
            dgvRecommen.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvRecommen.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));

            dgvRecommen.Columns["IsRecommen"].Width = 80;
            dgvRecommen.Columns["RecommenTime"].Width = 120;
            dgvRecommen.Columns["RecommenOperatePerson"].Width = 80;
            dgvRecommen.Columns["RecommenCompany"].Width = 150;
            dgvRecommen.Columns["RecommenPosition"].Width = 120;
            dgvRecommen.Columns["RecommenResult"].Width = 80;
            dgvRecommen.Columns["detail"].Width = 42;
            dgvRecommen.ReadOnly = true;
            dgvRecommen.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvRecommen_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 6) && e.RowIndex != -1)
            {
                recommenID = Convert.ToInt32(dgvRecommen.CurrentRow.Cells["id"].Value);
                foreach (OperateProcessRecode operateProcessRecode in listRecommen)
                {
                    if (operateProcessRecode.ID == recommenID)
                    {
                        InitRecommenDate(operateProcessRecode.IsRecommen, operateProcessRecode.RecommenTime, operateProcessRecode.RecommenOperatePerson,
                            operateProcessRecode.RecommenCompany, operateProcessRecode.RecommenPosition, operateProcessRecode.RecommenResult);
                    }
                }
            }
        }

        private void btnRecommenSave_Click(object sender, EventArgs e)
        {
            //if (CheckInitOperateProcessRecode())
            //{
            OperateProcessRecode operateProcessRecode = new OperateProcessRecode();
            operateProcessRecode.ID = recommenID;
            operateProcessRecode.BaseInfoID = id;
            operateProcessRecode.type = 2;
            //（23）简历推荐
            operateProcessRecode.IsRecommen = chkIsRecommen.Checked;
            operateProcessRecode.RecommenTime = dtpRecommenTime.Value;
            operateProcessRecode.RecommenOperatePerson = txtRecommenOperatePerson.Text.Trim();
            operateProcessRecode.RecommenCompany = txtRecommenCompany.Text.Trim();
            operateProcessRecode.RecommenPosition = txtRecommenPosition.Text.Trim();
            operateProcessRecode.RecommenResult = txtRecommenResult.Text.Trim();

            if (operateProcessRecodeAccess.AddOrUpdateOperateProcessRecode(operateProcessRecode))
            {
                PageCommon.ShowMessageByOK("保存成功。");
                recommenID = 0;
                InitRecommenDate(false, DateTime.Now, string.Empty, string.Empty, string.Empty, string.Empty);
                BindRecommen();
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
            //}
        }

        /// <summary>
        //（24）学历查询
        /// </summary>
        /// 
        private void btnEducationSurveySave_Click(object sender, EventArgs e)
        {
            //（24）学历查询
            BaseInfo baseInfo = new BaseInfo();
            baseInfo.ID = id;
            baseInfo.IsEducationSurvey = chkIsEducationSurvey.Checked;
            baseInfo.EducationSurveyOperatePerson = txtEducationSurveyOperatePerson.Text.Trim();
            baseInfo.EducationSurveyOrganization = txtEducationSurveyOrganization.Text.Trim();
            baseInfo.EducationSurveyResult = txtEducationSurveyResult.Text.Trim();

            if (baseInfoAccess.UpdateEducationSurvey(baseInfo))
            {
                PageCommon.ShowMessageByOK("保存成功。");
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
        }

        /// <summary>
        /// //（25）笔试
        /// </summary>

        private List<OperateProcessRecode> listWritenTest = new List<OperateProcessRecode>();
        private int writenTestID = 0;

        private void InitWritenTestDate(bool isWritenTest, DateTime writenTestTime, string writenTestOperatePerson, string writenTestSubject, string writenTestResult)
        {
            chkIsWritenTest.Checked = isWritenTest;
            dtpWritenTestTime.Value = writenTestTime;
            txtWritenTestOperatePerson.Text = writenTestOperatePerson;
            txtWritenTestSubject.Text = writenTestSubject;
            txtWritenTestResult.Text = writenTestResult;
        }

        private void BindWritenTest()
        {
            if (id != 0)
            {
                listWritenTest = operateProcessRecodeAccess.GetOperateProcessRecodes(id, 4);
                dgvWritenTest.Visible = true;
                dgvWritenTest.RowHeadersVisible = false;
                dgvWritenTest.DataSource = listWritenTest;
            }
            else
            {
                dgvWritenTest.Visible = false;
            }
        }


        private void dgvWritenTest_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvWritenTest.Columns.Clear();
            dgvWritenTest.Columns.Add(PageCommon.BuildColumn("是否面试", "IsWritenTest", "IsWritenTest", true));
            dgvWritenTest.Columns.Add(PageCommon.BuildColumn("时间", "WritenTestTime", "WritenTestTime", true));
            dgvWritenTest.Columns.Add(PageCommon.BuildColumn("操作人", "WritenTestOperatePerson", "WritenTestOperatePerson", true));
            dgvWritenTest.Columns.Add(PageCommon.BuildColumn("笔试题目", "WritenTestSubject", "WritenTestSubject", true));
            dgvWritenTest.Columns.Add(PageCommon.BuildColumn("结果", "WritenTestResult", "WritenTestResult", true));
            dgvWritenTest.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvWritenTest.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvWritenTest.Columns["detail"].Width = 42;
            dgvWritenTest.ReadOnly = true;
            dgvWritenTest.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

        }

        private void dgvWritenTest_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 5) && e.RowIndex != -1)
            {
                writenTestID = Convert.ToInt32(dgvWritenTest.CurrentRow.Cells["id"].Value);
                foreach (OperateProcessRecode operateProcessRecode in listWritenTest)
                {
                    if (operateProcessRecode.ID == writenTestID)
                    {
                        InitWritenTestDate(operateProcessRecode.IsWritenTest, operateProcessRecode.WritenTestTime, operateProcessRecode.WritenTestOperatePerson,
                            operateProcessRecode.WritenTestSubject, operateProcessRecode.WritenTestResult);
                    }
                }
            }
        }

        private void btnWritenTestSave_Click(object sender, EventArgs e)
        {
            //if (CheckInitOperateProcessRecode())
            //{
            OperateProcessRecode operateProcessRecode = new OperateProcessRecode();
            operateProcessRecode.ID = writenTestID;
            operateProcessRecode.BaseInfoID = id;
            operateProcessRecode.type = 4;
            //（25）笔试
            operateProcessRecode.IsWritenTest = chkIsWritenTest.Checked;
            operateProcessRecode.WritenTestTime = dtpWritenTestTime.Value;
            operateProcessRecode.WritenTestOperatePerson = txtWritenTestOperatePerson.Text.Trim();
            operateProcessRecode.WritenTestSubject = txtWritenTestSubject.Text.Trim();
            operateProcessRecode.WritenTestResult = txtWritenTestResult.Text.Trim();

            if (operateProcessRecodeAccess.AddOrUpdateOperateProcessRecode(operateProcessRecode))
            {
                PageCommon.ShowMessageByOK("保存成功。");
                writenTestID = 0;
                InitWritenTestDate(false, DateTime.Now, string.Empty, string.Empty, string.Empty);
                BindWritenTest();
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
            //}
        }

        /// <summary>
        ///（26）面试
        /// </summary>

        private List<OperateProcessRecode> listInterview = new List<OperateProcessRecode>();
        private int InterviewID = 0;

        private void InitInterviewDate(bool isIsInterview, DateTime interviewTime, string interviewOperatePerson, string interviewPerson, string interviewCompany, string interviewPosition, string interviewCharacter, string interviewResult)
        {
            chkIsInterview.Checked = isIsInterview;
            dtpInterviewTime.Value = interviewTime;
            txtInterviewOperatePerson.Text = interviewOperatePerson;
            txtInterviewPerson.Text = interviewPerson;
            txtInterviewCompany.Text = interviewCompany;
            txtInterviewPosition.Text = interviewPosition;
            txtInterviewCharacter.Text = interviewCharacter;
            txtInterviewResult.Text = interviewResult;
        }

        private void BindInterview()
        {
            if (id != 0)
            {
                listInterview = operateProcessRecodeAccess.GetOperateProcessRecodes(id, 5);
                dgvInterview.Visible = true;
                dgvInterview.RowHeadersVisible = false;
                dgvInterview.DataSource = listInterview;
            }
            else
            {
                dgvInterview.Visible = false;
            }
        }


        private void dgvInterview_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvInterview.Columns.Clear();
            dgvInterview.Columns.Add(PageCommon.BuildColumn("是否面试", "IsInterview", "IsInterview", true));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("时间", "InterviewTime", "InterviewTime", true));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("操作人", "InterviewOperatePerson", "InterviewOperatePerson", true));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("面试官", "InterviewPerson", "InterviewPerson", true));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("面试单位/公司", "InterviewCompany", "InterviewCompany", true));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("面试岗位", "InterviewPosition", "InterviewPosition", true));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("面试性质", "InterviewCharacter", "InterviewCharacter", true));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("结果", "InterviewResult", "InterviewResult", true));

            dgvInterview.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvInterview.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvInterview.Columns["IsInterview"].Width = 80;
            dgvInterview.Columns["InterviewTime"].Width = 100;
            dgvInterview.Columns["InterviewOperatePerson"].Width = 70;
            dgvInterview.Columns["InterviewPerson"].Width = 70;
            dgvInterview.Columns["InterviewCompany"].Width = 100;
            dgvInterview.Columns["InterviewPosition"].Width = 80;
            dgvInterview.Columns["InterviewCharacter"].Width = 80;
            dgvInterview.Columns["InterviewResult"].Width = 80;
            dgvInterview.Columns["detail"].Width = 42;
            dgvInterview.ReadOnly = true;
            dgvInterview.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvInterview_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 8) && e.RowIndex != -1)
            {
                InterviewID = Convert.ToInt32(dgvInterview.CurrentRow.Cells["id"].Value);
                foreach (OperateProcessRecode operateProcessRecode in listInterview)
                {
                    if (operateProcessRecode.ID == InterviewID)
                    {
                        InitInterviewDate(operateProcessRecode.IsInterview, operateProcessRecode.InterviewTime, operateProcessRecode.InterviewOperatePerson,
                            operateProcessRecode.InterviewPerson, operateProcessRecode.InterviewCompany, operateProcessRecode.InterviewPosition,
                            operateProcessRecode.InterviewCharacter, operateProcessRecode.InterviewResult);
                    }
                }
            }
        }

        private void btnInterviewSave_Click(object sender, EventArgs e)
        {
            //if (CheckInitOperateProcessRecode())
            //{
            OperateProcessRecode operateProcessRecode = new OperateProcessRecode();
            operateProcessRecode.ID = InterviewID;
            operateProcessRecode.BaseInfoID = id;
            operateProcessRecode.type = 5;
            //（26）面试
            operateProcessRecode.IsInterview = chkIsInterview.Checked;
            operateProcessRecode.InterviewTime = dtpInterviewTime.Value;
            operateProcessRecode.InterviewOperatePerson = txtInterviewOperatePerson.Text.Trim();
            operateProcessRecode.InterviewPosition = txtInterviewPosition.Text.Trim();
            operateProcessRecode.InterviewPerson = txtInterviewPerson.Text.Trim();
            operateProcessRecode.InterviewCompany = txtInterviewCompany.Text.Trim();
            operateProcessRecode.InterviewCharacter = txtInterviewCharacter.Text.Trim();
            operateProcessRecode.InterviewResult = txtInterviewResult.Text.Trim();

            if (operateProcessRecodeAccess.AddOrUpdateOperateProcessRecode(operateProcessRecode))
            {
                PageCommon.ShowMessageByOK("保存成功。");
                InterviewID = 0;
                InitInterviewDate(false, DateTime.Now, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                BindInterview();
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
            //}
        }

        /// <summary>
        ///（27）背景调查
        /// </summary>

        private void btnSurveySave_Click(object sender, EventArgs e)
        {
            //（27）背景调查

            BaseInfo baseInfo = new BaseInfo();
            baseInfo.ID = id;
            baseInfo.IsSurvey = chkIsSurvey.Checked;
            baseInfo.SurveyTime = dtpSurveyTime.Value;
            baseInfo.SurveyOperatePerson = txtSurveyOperatePerson.Text.Trim();
            baseInfo.SurveyWorkTruth = txtSurveyWorkTruth.Text.Trim();
            baseInfo.SurveyEveryTruth = txtSurveyEveryTruth.Text.Trim();
            baseInfo.SurveyExceptionRemark = txtSurveyExceptionRemark.Text.Trim();

            if (baseInfoAccess.UpdateSurvey(baseInfo))
            {
                PageCommon.ShowMessageByOK("保存成功。");
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
            //}
        }

        /// <summary>
        ///（28）薪酬沟通
        /// </summary>

        private List<OperateProcessRecode> listSalaryCommunication = new List<OperateProcessRecode>();
        private int salaryCommunicationID = 0;

        private void InitSalaryCommunicationDate(bool isSalaryCommunications, DateTime salaryCommunicationsTime, string salaryCommunicationsOperatePerson, string salaryCommunications, string salaryCommunicationsResult)
        {
            chkIsSalaryCommunications.Checked = isSalaryCommunications;
            dtpSalaryCommunicationsTime.Value = salaryCommunicationsTime;
            txtSalaryCommunicationsOperatePerson.Text = salaryCommunicationsOperatePerson;
            txtSalaryCommunications.Text = salaryCommunications;
            txtSalaryCommunicationsResult.Text = salaryCommunicationsResult;
        }

        private void BindSalaryCommunicationDate()
        {
            if (id != 0)
            {
                listSalaryCommunication = operateProcessRecodeAccess.GetOperateProcessRecodes(id, 7);
                dgvSalaryCommunications.Visible = true;
                dgvSalaryCommunications.RowHeadersVisible = false;
                dgvSalaryCommunications.DataSource = listSalaryCommunication;

            }
            else
            {
                dgvSalaryCommunications.Visible = false;
            }
        }

        private void dgvSalaryCommunications_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            dgvSalaryCommunications.Columns.Clear();
            dgvSalaryCommunications.Columns.Add(PageCommon.BuildColumn("是否沟通", "IsSalaryCommunications", "IsSalaryCommunications", true));
            dgvSalaryCommunications.Columns.Add(PageCommon.BuildColumn("时间", "SalaryCommunicationsTime", "SalaryCommunicationsTime", true));
            dgvSalaryCommunications.Columns.Add(PageCommon.BuildColumn("操作人", "SalaryCommunicationsOperatePerson", "SalaryCommunicationsOperatePerson", true));
            dgvSalaryCommunications.Columns.Add(PageCommon.BuildColumn("沟通待遇", "SalaryCommunications", "SalaryCommunications", true));
            dgvSalaryCommunications.Columns.Add(PageCommon.BuildColumn("结果", "SalaryCommunicationsResult", "SalaryCommunicationsResult", true));
            dgvSalaryCommunications.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            dgvSalaryCommunications.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            dgvSalaryCommunications.Columns["detail"].Width = 42;
            dgvSalaryCommunications.ReadOnly = true;
            dgvSalaryCommunications.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private void dgvSalaryCommunications_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 5) && e.RowIndex != -1)
            {
                salaryCommunicationID = Convert.ToInt32(dgvSalaryCommunications.CurrentRow.Cells["id"].Value);
                foreach (OperateProcessRecode operateProcessRecode in listSalaryCommunication)
                {
                    if (operateProcessRecode.ID == salaryCommunicationID)
                    {
                        InitSalaryCommunicationDate(operateProcessRecode.IsSalaryCommunications, operateProcessRecode.SalaryCommunicationsTime,
                            operateProcessRecode.SalaryCommunicationsOperatePerson, operateProcessRecode.SalaryCommunications, operateProcessRecode.SalaryCommunicationsResult);
                    }
                }
            }
        }

        private void btnSalaryCommunicationSave_Click(object sender, EventArgs e)
        {
            //if (CheckInitOperateProcessRecode())
            //{
            OperateProcessRecode operateProcessRecode = new OperateProcessRecode();
            operateProcessRecode.ID = salaryCommunicationID;
            operateProcessRecode.BaseInfoID = id;
            operateProcessRecode.type = 7;
            //（28）薪酬沟通
            operateProcessRecode.IsSalaryCommunications = chkIsSalaryCommunications.Checked;
            operateProcessRecode.SalaryCommunicationsTime = dtpSalaryCommunicationsTime.Value;
            operateProcessRecode.SalaryCommunicationsOperatePerson = txtSalaryCommunicationsOperatePerson.Text.Trim();
            operateProcessRecode.SalaryCommunications = txtSalaryCommunications.Text.Trim();
            operateProcessRecode.SalaryCommunicationsResult = txtSalaryCommunicationsResult.Text.Trim();

            if (operateProcessRecodeAccess.AddOrUpdateOperateProcessRecode(operateProcessRecode))
            {
                PageCommon.ShowMessageByOK("保存成功。");
                salaryCommunicationID = 0;
                InitSalaryCommunicationDate(false, DateTime.Now, string.Empty, string.Empty, string.Empty);
                BindSalaryCommunicationDate();
            }
            else
            {
                PageCommon.ShowMessageByOK("保存失败。");
            }
            //}
        }
        #endregion
        #region  （七）结果记录

        private List<ResultRecord> listResultRecord;
        private int resultRecordID = 0;

        private void InitResultRecord()
        {
            BindResultRecord();
            PageCommon.FormatDateTimePickerByYearMonthDay(dtpEmployTime);
        }

        private void InitDate(bool isIsEmploy, DateTime employTime, string employCompany, string employDepartment, string employPosition, string employSalar)
        {
            chkIsEmploy.Checked = isIsEmploy;
            dtpEmployTime.Value = employTime;
            txtEmployCompany.Text = employCompany;
            txtEmployDepartment.Text = employDepartment;
            txtEmployPosition.Text = employPosition;
            txtEmploySalar.Text = employSalar.ToString();
        }

        private void BindResultRecord()
        {
            if (id != 0)
            {
                listResultRecord = resultRecordAccess.GetResultRecords(id);
                DgvResultRecord.Visible = true;
                DgvResultRecord.RowHeadersVisible = false;
                DgvResultRecord.DataSource = listResultRecord;
            }
            else
            {
                DgvResultRecord.Visible = false;
            }
        }

        private void DgvResultRecord_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            DgvResultRecord.Columns.Clear();
            DgvResultRecord.Columns.Add(PageCommon.BuildColumn("是否录用", "IsEmploy", "IsEmploy", true));
            DgvResultRecord.Columns.Add(PageCommon.BuildColumn("录用时间", "EmployTime", "EmployTime", true));
            DgvResultRecord.Columns.Add(PageCommon.BuildColumn("录用单位", "EmployCompany", "EmployCompany", true));
            DgvResultRecord.Columns.Add(PageCommon.BuildColumn("录用部门", "EmployDepartment", "EmployDepartment", true));
            DgvResultRecord.Columns.Add(PageCommon.BuildColumn("录用岗位", "EmployPosition", "EmployPosition", true));
            DgvResultRecord.Columns.Add(PageCommon.BuildColumn("薪酬待遇", "EmploySalar", "EmploySalar", true));
            DgvResultRecord.Columns.Add(PageCommon.BuildImagesColumn("", "detail", "", true, Application.StartupPath + "\\images\\detail_bg.png"));
            DgvResultRecord.Columns.Add(PageCommon.BuildColumn("id", "id", "ID", false));
            DgvResultRecord.Columns["IsEmploy"].Width = 80;
            DgvResultRecord.Columns["EmployTime"].Width = 120;
            DgvResultRecord.Columns["EmployCompany"].Width = 80;
            DgvResultRecord.Columns["EmployDepartment"].Width = 80;
            DgvResultRecord.Columns["EmployPosition"].Width = 80;
            DgvResultRecord.Columns["EmploySalar"].Width = 80;
            DgvResultRecord.Columns["detail"].Width = 42;
            DgvResultRecord.ReadOnly = true;
            DgvResultRecord.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
        }

        private bool CheckResultRecordNull()
        {
            bool isNotNull = false;
            if (string.IsNullOrEmpty(txtEmployCompany.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入录用单位。");
                txtEmployCompany.Focus();
            }
            else if (string.IsNullOrEmpty(txtEmployDepartment.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入录用部门。");
                txtEmployDepartment.Focus();
            }
            else if (string.IsNullOrEmpty(txtEmployPosition.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入录用岗位。");
                txtEmployPosition.Focus();
            }
            else if (string.IsNullOrEmpty(txtEmploySalar.Text.Trim()))
            {
                PageCommon.ShowMessageByOK("请输入薪酬待遇。");
                txtEmploySalar.Focus();

            }
            else
                isNotNull = true;
            return isNotNull;
        }

        private void DgvResultRecord_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if ((e.ColumnIndex == 6) && e.RowIndex != -1)
            {
                resultRecordID = Convert.ToInt32(DgvResultRecord.CurrentRow.Cells["id"].Value);
                foreach (ResultRecord resultRecord in listResultRecord)
                {
                    if (resultRecord.ID == resultRecordID)
                    {
                        InitDate(resultRecord.IsEmploy, resultRecord.EmployTime, resultRecord.EmployCompany, resultRecord.EmployDepartment, resultRecord.EmployPosition, resultRecord.EmploySalar.ToString());
                    }
                }
            }
        }

        private void btnResultRecord_Click(object sender, EventArgs e)
        {
            if (CheckResultRecordNull())
            {
                ResultRecord resultRecord = new ResultRecord();
                resultRecord.ID = resultRecordID;

                resultRecord.IsEmploy = chkIsEmploy.Checked;
                resultRecord.EmployTime = dtpEmployTime.Value;
                resultRecord.EmployCompany = txtEmployCompany.Text.Trim();
                resultRecord.EmployDepartment = txtEmployDepartment.Text.Trim();
                resultRecord.EmployPosition = txtEmployPosition.Text.Trim();
                resultRecord.EmploySalar = Convert.ToDouble(txtEmploySalar.Text.Trim());
                resultRecord.BaseInfoID = id;

                if (resultRecordAccess.AddOrUpdateResultRecord(resultRecord))
                {
                    PageCommon.ShowMessageByOK("保存成功。");
                    BindResultRecord();
                    InitDate(false, DateTime.Now, string.Empty, string.Empty, string.Empty, string.Empty);
                    resultRecordID = 0;
                }
                else
                {
                    PageCommon.ShowMessageByOK("保存失败。");
                }
            }
        }

        #endregion

        private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == 8))
            {
                e.Handled = false;
            }

            else
            {
                //MessageBox.Show("只能为数字！");
                e.Handled = true;
            }
        }

        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            e.Cancel = id == 0;
        }
    }
}
